function  [S,Size] = expandFromPointNew( inputFileName,sliceNumber,outputFileName)
%EXPANDFROMPOINTNEW Summary of this function goes here
%   Detailed explanation goes here
    DIFF_FACTOR = 0.1;

    %load the nifti file and extract the relevant slice
    image = load_nifti(inputFileName);
    origSlice = image(:,:,sliceNumber);
    
    %display the slice and wait for click from the user
    %we normal the values of the displayed image in order to be able to see most of the image
    figure(1);
    imshow(origSlice./max(origSlice(:)));
    [x,y] = ginput(1);
    x = int32(x);
    y = int32(y);
    
    origGrayLevel = image(y,x,sliceNumber);
    %prepare the segmentation matrix
    TH = zeros(size(image));
    
    %mark color-related voxels with "1"
    TH(logical((origGrayLevel*(1-DIFF_FACTOR)<=image) & (origGrayLevel*(1+DIFF_FACTOR)>=image))) = 1;
    
    %mark the voxels that's in the connected component of the relevant
    %voxel with '1'
    CC = bwconncomp(TH,26);
    L = labelmatrix(CC);
    
    S = zeros(size(image));
    S(CC.PixelIdxList{L(y,x,sliceNumber)})=1;
    Size=length(CC.PixelIdxList{L(y,x,sliceNumber)});
    
    save_nifti(S,outputFileName,2);
    close(1);
end



























function  [S] = expandFromPointNew111( inputFileName,sliceNumber,outputFileName)
%EXPANDFROMPOINTNEW Summary of this function goes here
%   Detailed explanation goes here
DIFF_FACTOR = 0.1;
    %load the nifti file and extract the relevant slice
    image = load_nifti(inputFileName);
    origSlice = image(:,:,sliceNumber);
    
    %display the slice and wait for click from the user
    %we normal the values of the displayed image in order to be able to see most of the image
    imshow(origSlice./max(origSlice(:)));
    [y,x] = ginput(1)
    x = int32(x);
    y = int32(y);
    
    origGrayLevel = origSlice(x,y);
    %prepare the segmentation matrix
    segMatrix = zeros(size(image));
    S = segMatrix;
    
    %mark color-related voxels with "1"
    segMatrix(logical((origGrayLevel*(1-DIFF_FACTOR)<=image) & (origGrayLevel*(1+DIFF_FACTOR)>=image))) = 1;
    
    %find all connected component of "1"s
    CC = bwconncomp(segMatrix,26);
    
    PixelIdxList = CC.PixelIdxList;
    
    %find the connected component which the clicked pixels belongs to
    origPixelIndex = sliceNumber*size(origSlice,1)*size(origSlice,2) + (y-1)*size(origSlice,1) + x;
    for i=1:length(PixelIdxList)    
        
        res = find(PixelIdxList{i} == origPixelIndex);
        
        if (size(res,1) == 0)
            continue;
        end
        
        %mark all the connected component's voxels
        S(PixelIdxList{i}) = 1;
        break;
        
    end
   
    save_nifti(S,outputFileName,2);
    
end

